package com.xintai.sparepart.spareandpart.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xintai.common.constant.Constants;
import com.xintai.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xintai.sparepart.spareandpart.mapper.BeiKuweiMapper;
import com.xintai.sparepart.spareandpart.domain.BeiKuwei;
import com.xintai.sparepart.spareandpart.service.IBeiKuweiService;

/**
 * 库位Service业务层处理
 *
 * @author xintai
 * @date 2020-12-23
 */
@Service
public class BeiKuweiServiceImpl implements IBeiKuweiService
{
    @Autowired
    private BeiKuweiMapper beiKuweiMapper;

    /**
     * 查询库位
     *
     * @param kuweiId 库位ID
     * @return 库位
     */
    @Override
    public BeiKuwei selectBeiKuweiById(Long kuweiId)
    {
        return beiKuweiMapper.selectBeiKuweiById(kuweiId);
    }

    /**
     * 查询库位列表
     *
     * @param beiKuwei 库位
     * @return 库位
     */
    @Override
    public List<BeiKuwei> selectBeiKuweiList(BeiKuwei beiKuwei)
    {
        return beiKuweiMapper.selectBeiKuweiList(beiKuwei);
    }

    /**
     * 新增库位
     *
     * @param beiKuwei 库位
     * @return 结果
     */
    @Override
    public int insertBeiKuwei(BeiKuwei beiKuwei)
    {
        beiKuwei.setKuweiTime(new Date());
        beiKuwei.setKuweiUid(SecurityUtils.getLoginUser().getUser().getUserId());
        return beiKuweiMapper.insertBeiKuwei(beiKuwei);
    }

    /**
     * 修改库位
     *
     * @param beiKuwei 库位
     * @return 结果
     */
    @Override
    public int updateBeiKuwei(BeiKuwei beiKuwei)
    {
        return beiKuweiMapper.updateBeiKuwei(beiKuwei);
    }

    /**
     * 批量删除库位
     *
     * @param kuweiIds 需要删除的库位ID
     * @return 结果
     */
    @Override
    public int deleteBeiKuweiByIds(Long[] kuweiIds)
    {
        Map<String, Object> map = new HashMap<>();
        map.put("kuweiId",kuweiIds);
        map.put("kuweiIsdel",Constants.FAIL);
        return beiKuweiMapper.deleteBeiKuweiByIds(map);
    }

    /**
     * 删除库位信息
     *
     * @param kuweiId 库位ID
     * @return 结果
     */
    @Override
    public int deleteBeiKuweiById(Long kuweiId)
    {
        return beiKuweiMapper.deleteBeiKuweiById(kuweiId,Constants.FAIL);
    }

    /**
     * 不同仓库可重名
     * @param cangkuId
     * @param kuweiName
     * @return
     */
    @Override
    public boolean selectkuweiNamesake(Integer cangkuId, String kuweiName) {
        if (beiKuweiMapper.selectkuweiNamesake(cangkuId,kuweiName)>0){
            return true;
        }
        return false;
    }
}
